﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MindFusion;
using MindFusion.Diagramming;
using System.Drawing;
using MindFusion.Drawing;

namespace SSShell
{
    public class IconNode : ShapeNode
    {
        public IconNode()
        {
            //defaultIcon = new Bitmap(48, 48);

            //Graphics graphics = Graphics.FromImage(defaultIcon);
            //Font font = new Font("Arial", 48, FontStyle.Bold, GraphicsUnit.Pixel);

            //graphics.FillRectangle(Brushes.Transparent, 0, 0, 48, 48);
            //graphics.DrawString("?", font, Brushes.Black, 0, 0);

            //font.Dispose();
            //graphics.Dispose();
        }

        public IconNode(Diagram diagram,Color Col,SizeF ssixe)
            : base(diagram)
        {
            //icon = defaultIcon;
            //label = "Label";
            //format = new StringFormat();
            //format.Alignment = StringAlignment.Center;
            //format.LineAlignment = StringAlignment.Center;
           
            ColOfNode = Col;
            Bounds = new RectangleF(Bounds.Location, new SizeF(15,7));// CalculateSize());
        }

        public Color ColOfNode
        { set; get; }


        public override void Draw(IGraphics graphics, RenderOptions options)
        {
            //Rectangle iconSizePixels = new Rectangle(0, 0, icon.Width, icon.Height);
            //RectangleF imageSize = MindFusion.Utilities.DeviceToDoc(graphics, iconSizePixels);
            base.Draw(graphics, options);
            // Draw the icon center at the top
            //graphics.DrawImage(icon, Bounds.X + Bounds.Width / 2 - imageSize.Width / 2, Bounds.Y);
           // graphics.DrawEllipse(new System.Drawing.Pen(ColOfNode), Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);
            graphics.DrawRectangle(new System.Drawing.Pen(ColOfNode), Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height);
            //DrawImage(icon, Bounds.X + Bounds.Width / 2 - imageSize.Width / 2, Bounds.Y);

            // Draw the label at the bottom
            //RectangleF labelBounds = RectangleF.FromLTRB(
            //    Bounds.X, Bounds.Y + imageSize.Height, Bounds.Right, Bounds.Bottom);

            //graphics.DrawString(label,
            //    Font, Brushes.Black, labelBounds, format);
        }

        public override void DrawShadow(IGraphics graphics, RenderOptions options)
        {
        }

        //private SizeF CalculateSize()
        //{
        //    Bitmap tempImage = new Bitmap(1, 1);
        //    Graphics graphics = Graphics.FromImage(tempImage);
        //    IGraphics measureGraphics = new GdiGraphics(graphics);

        //    measureGraphics.PageUnit = Parent.MeasureUnit;
        //    Rectangle iconSizePixels = new Rectangle(0, 0, icon.Width, icon.Height);
        //    RectangleF imageSize = MindFusion.Utilities.DeviceToDoc(measureGraphics, iconSizePixels);

        //    measureGraphics.Dispose();
        //    tempImage.Dispose();

        //    SizeF textSize = Parent.MeasureString(label, Font, int.MaxValue, format);

        //    return new SizeF(
        //        Math.Max(imageSize.Width, textSize.Width),
        //        imageSize.Height + textSize.Height);
        //}

        protected override void UpdateCreate(PointF current)
        {
            base.UpdateCreate(current);
            Bounds = new RectangleF(current, new SizeF(5, 5)/*CalculateSize()*/);
        }

        //protected override void SaveTo(System.IO.BinaryWriter writer, PersistContext ctx)
        //{
        //    base.SaveTo(writer, ctx);

        //    // Save the label using the standard .NET BinaryWriter
        //    writer.Write(label);

        //    // Save the image using the MindFusion.Diagramming built-in image saving code,
        //    // which stores the contents of shared images only once.
        //    ctx.SaveImage(icon);
        //}

        //protected override void LoadFrom(System.IO.BinaryReader reader, PersistContext ctx)
        //{
        //    base.LoadFrom(reader, ctx);

        //    label = reader.ReadString();
        //    icon = ctx.LoadImage();
        //}


        //public Image Icon
        //{
        //    get { return icon; }
        //    set
        //    {
        //        icon = value;
        //        Bounds = new RectangleF(Bounds.Location, CalculateSize());
        //    }
        //}

        //public string Label
        //{
        //    get { return label; }
        //    set
        //    {
        //        label = value;
        //        Bounds = new RectangleF(Bounds.Location, CalculateSize());
        //    }
        //}


        //private Image icon;
        //private string label;
        //private StringFormat format;

        //static private Image defaultIcon;
    }
}
